<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <!-- 登录card -->
    <div class="tabs">
      <el-tabs
        v-model="activeName"
        class="demo-tabs"
        type="border-card"
        stretch
      >
        <!-- 账号登录选项卡 -->
        <el-tab-pane name="account">
          <template #label>
            <div class="label">
              <el-icon><UserFilled /></el-icon>
              <span class="label-text">账号登录</span>
            </div>
          </template>
          <pane-account ref="accountRef"></pane-account>
        </el-tab-pane>
        <!-- 手机登录选项卡 -->
        <el-tab-pane label="手机登录" name="phone">
          <template #label>
            <div class="label">
              <el-icon><Iphone /></el-icon>
              <span class="label-text">手机登录</span>
            </div>
          </template>
          <pane-phone></pane-phone>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 底部区域 -->
    <div class="controls">
      <el-checkbox label="记住密码" v-model="isRemPwb" size="large" />
      <el-link type="primary" :underline="false">忘记密码</el-link>
    </div>
    <el-button
      class="login-btn"
      size="large"
      type="primary"
      @click="handleLogin"
      >立即登录</el-button
    >
  </div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import paneAccount from './pane-account.vue'
import panePhone from './pane-phone.vue'
import { localCache } from '@/utils/cache'
const isRemPwb = ref<boolean>(localCache.getCache('isRemPwb') ?? false)
const activeName = ref('account')
const accountRef = ref<InstanceType<typeof paneAccount>>()
watch(isRemPwb, (newVal: boolean) => {
  localCache.setCache('isRemPwb', newVal)
})

function handleLogin() {
  if (activeName.value === 'account') {
    // 1.获取子组件实例
    accountRef.value?.loginAction(isRemPwb.value)
  } else if (activeName.value === 'phone') {
    console.log('手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  width: 330px;
  margin-bottom: 150px;
  .tabs {
    margin-top: 10px;

    .label {
      display: flex;
      justify-content: center;
      align-items: center;

      .label-text {
        margin-left: 5px;
      }
    }
  }
  .title {
    text-align: center;
  }
  .controls {
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    width: 100%;
    margin-top: 10px;
    // --el-button-size: 50px;
  }
}
</style>
